Micron Document




Java syntax
part 15/46 · 86.7 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Enhanced for loops have been available since J2SE 5.0. This type of loop uses built-in iterators over arrays and collections to return each item in the given collection. Every element is returned and reachable in the context of the code block. When the block is executed, the next item is returned until there are no items remaining. Unlike C#, this kind of loop does not involve a special keyword, but instead uses a different notation style.

for (int i : intArray) {
doSomething(i);
}

Jump statements

Labels

Labels are given points in code used by break and continue statements. The Java goto keyword cannot be used to jump to specific points in code.

start:
someMethod();

break statement

The break statement breaks out of the closest loop or switch statement. Execution continues in the statement after the terminated statement, if any.

for (int i = 0; i < 10; i++) {
while (true) {
break;
}
// Will break to this point
}

It is possible to break out of the outer loop using labels:

outer:
for (int i = 0; i < 10; i++) {
while (true) {
break outer;
}
}
// Will break to this point

continue statement

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────